home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / menfram.exe / MENFRAME.DOC < prev    next >
Text File  |  1992-12-30  |  3KB  |  112 lines

  1.  
  2. MenFrame defines the new TV type TMenuFrame, which implements a sytem menu
  3. for ordinary windows. If you click on the close icon of the window, you will
  4. open a menu, that contains the items
  5.  
  6.      Item                           Command
  7.  
  8.      Zoom                           cmZoom
  9.      Move/Size                      cmResize
  10.      Close                          cmClose
  11.      Next Window                    cmNext
  12.  
  13. Each of these items simply sends a predefined TV command to it's owner.
  14. The effect will be as you expect ( if you didn't redefine one of these
  15. commands of course )
  16.  
  17. Using TMenuFrame is simple. You just have to write a new InitFrame procedure
  18. for your windows class, that looks like:
  19.  
  20. procedure TMyWindow.InitFrame;
  21.  
  22. var
  23.    R : TRect;
  24.  
  25. begin
  26.   GetExtent(R);
  27.   frame:= new TMenuFrame(R);
  28. end;
  29.  
  30. You may also exent the menu if you wish. TMenuFrame defines a procedure
  31. AppendMenu(pM:PMenuItem).
  32.  
  33. Suppose you want to define two new items dummy1 and dummy2. Your InitFrame
  34. procedure then could look like this
  35.  
  36. procedure TMyWindow.InitFrame;
  37.  
  38. var
  39.    R : TRect;
  40.  
  41. begin
  42.   GetExtent(R);
  43.   frame:= new TMenuFrame(R);
  44.   if frame<>Nil then
  45.   begin
  46.     PMenuFrame(frame)^.AppendMenu(
  47.       NewItem('Dummy2', 'F9', kbF9, cmDummy2, hcNoContext,
  48.       NewItem('Dummy1', 'Ctlr-F9', kbCtrlF9, cmDummy1, hcNoContext,
  49.       NewLine(
  50.       Nil))));
  51.   end
  52. end;
  53.  
  54. As you can see in the example, the structure you want to append to the system
  55. menu must be inserted in invers order.
  56.  
  57. Deleting items from the menu is possible too. You just have to use the DeleteMenu
  58. Procedure. DeleteMenu wants a ShortInt as parameter, which represents the
  59. position of the item within the menu. 0 is the first ( top ) item.
  60.  
  61. For example PMenuFrame(frame)^.DeleteMenu(1) would delete the second item in
  62. the menu ( Move/Size by default ).
  63.  
  64. Unfortunatly i used some code from the Borland TV library source. Thus
  65. i cannot supply you with the source of TMenuFrame. Following you find the
  66. interface section of the unit:
  67.  
  68. Unit MenFrame;
  69.  
  70. Interface
  71.  
  72. uses Drivers, Objects, Views, Menus, App;
  73.  
  74. type
  75.   PMenuFrame = ^TMenuFrame;
  76.   TMenuFrame = Object(TFrame)
  77.             last     : PMenuItem;
  78.             items    : ShortInt;
  79.             constructor Init(var Bounds : TRect);
  80.             procedure HandleEvent(var Event: TEvent); virtual;
  81.             procedure AppendMenu(pM:PMenuItem);
  82.             procedure DeleteMenu(b : ShortInt);
  83.           end;
  84.  
  85. implementation
  86.  
  87. As usual .tpu is the real mode and .tpp the protected mode unit.
  88.  
  89. You will need Borland Pascal 7.0 to use these units.
  90.  
  91. There is no kind of copyright on the code. ( As a matter of fact, the code
  92. is so simple, that according to the german laws i do not even have the right
  93. to claim a copyright on it )
  94.  
  95. I wrote this code in order to demonstrate, that this kind of feature is easy
  96. to implement in TV. ( This kind of system menu is standard for Visual Basic
  97. for DOS forms and some friends argued, that it would be difficult to enhance
  98. TV with such a feature ). Thus I have not tested the code extensively. If you
  99. run into any problems I would be glad, if you would report the error to me.
  100.  
  101. My email address is horstmei.abg@sni.de, my compuserve account is 100012,3451.
  102.  
  103.  
  104.  
  105. Jens Horstmeier
  106. Finkenstr. 6
  107. DW-8901 Langweid am Lech
  108. Germany
  109.  
  110.  
  111.  
  112.